# -*- coding:utf-8 -*-

import requests
from lxml import etree
from fake_useragent import UserAgent
from http import cookiejar
import json
from datetime import datetime


class Test_Get():
    def __init__(self):
        #声明一个CookieJar对象实例来保存cookie
        self.cookie = cookiejar.CookieJar()
        ua = UserAgent(use_cache_server=False)  # 禁用服务器缓存
        self.headers = {
            # "User-Agent": ua.random
            "authority": "www.lazada.com.ph",
            "method": "GET",
            "path": "/shop-motorcycle-helmets/?ajax=true&page=2&spm=a2o4l.home.cate_12_2.1.239e6db4wGmMoi",
            "scheme": "https",
            "accept": "application/json, text/plain, */*",
            "accept-encoding": "gzip, deflate, br",
            "accept-language": "zh-CN,zh;q=0.9",
            "cookie": "t_fv=1579834282586; t_uid=XlweROtkyoDj4pDHetH78exnvFi6FRDc; t_sid=vKTvXfXOxcQk54BohrTvKcmb9ko73Huz; utm_channel=NA; lzd_cid=bc640808-c3c6-495e-f3d0-59bf2447e609; cna=qEmxFpDMNwMCASo3xw6DAKHO; lzd_sid=1a55ea995642fb823c074f2cd00c175d; _m_h5_tk=94ae24f71ce97e329d05b04a1d92a1dd_1579842561403; _m_h5_tk_enc=8720222e957c05c7e9bf0d8cf16c3ba2; hng=PH|en-PH|PHP|608; userLanguageML=en; _bl_uid=sCkXX5Lhrdwk0yjdLjn016slIXdk; _tb_token_=f53eb5eeb8356; _ga=GA1.3.564526329.1579834332; _gid=GA1.3.741533769.1579834332; x5sec=7b22617365727665722d6c617a6164613b32223a226361646463363931316632306230613032666661353763363337653537333931434c32377166454645495464313762343475473645673d3d227d; JSESSIONID=F374C7A7E7FD04AD01C05484F35F04D6; l=cBTW8T_IQrGsMsQ3BOfa-urza77O4HOf5PVzaNbMiIB1twW_Up_F0HwUyHZ2O3QQE95xiFKPe0F7oRHBPkU38xTnFaKo7ZLiR; isg=BB4esRQ7zGPEiBgHo7xnEmQfb7Rg3-JZnROkXciw1WZC67TFNWtQaE7N4_dnVtpx",
            "dnt": "1",
            "referer": "https://www.lazada.com.ph/shop-motorcycle-helmets/?page=2&spm=a2o4l.home.cate_12_2.1.239e6db4wGmMoi",
            "sec-fetch-mode": "cors",
            "sec-fetch-site": "same-origin",
            "user-agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/79.0.3945.130 Safari/537.36",
            "x-csrf-token": "f53eb5eeb8356",
            "x-requested-with": "XMLHttpRequest",
            "x-ua": '122#mxm7wJXGEEJSmDpZMEpJEJponDJE7SNEEP7rEJ+/f9t/2oQLpo7iEDpWnDEeK51HpyGZp9hBuDEEJFOPpC76EJponDJL7gNpEPXZpJRgu4Ep+FQLpoGUEJLWn4yP7SQEEyuLpERLo7G9prrMgcmVdL1hh3+rRldhkxrTWJHMfwc0t8q8BMZVwmx5BIKP91c2ZSFYpbeN9a0BJZLUhHbDMYG9Wuq6LWzZFuABNEPHngp1uOf6ct9v6gcFf5rvFWxHKRCSTZWfzKkdvEKEELXc3n+61MMjFf1YK6RqxB1QBf8cOX6ORYl48o+UJDEEyB3tqWZ0HsO8ngL4uO8pELVZGWZRfsTbyFfDmSfbEEpMnMp1uOIEELXZ8oL6JNEERBfmqM32E5pangL4uljEDLVr8CpUJ4bEyNRDqMfImEpxngLVeyR9E5G+UoC7H4j2tDaIBYkIGRkP+8qXX7Aa0wPZEIInCdDTYyoppuRMzX7ge9KoaFr0DPHek/08G17AYbJH0hlh09gLZBhbSCbapQO5qjH7PWeate60pwFmITwUsRB3D4ndOS/okBlNdVLhJhgTInNXmDXHYCbmR+r816VEUcobC2YO6ob/BVR+lpriTcilYTXdqa0jpB7wQzVLHsHKnpBPNZND+SFa7AwwHIRfAXIm6pCnE5jbIqQxnpWu+N43r9MQ9TZgd0g68cG8gexRnSCZ/iNz0njn+BhyRYwrqr32+V1CwMjolpDe6hSSV8AnQeHQOdCMjwAr38NeC+saEOLbFHgDhStoDSEx5E1cPBZZXp9duu0RCNd8glvFXqRrgRT7dU0e/PEhdD3wIj4+xM99zDgDLBHWaf3TlMDKoQIBcWfVD995x/NasqwS5iPjI6Ay4Jz8wTgZV3YRv2g05Ncg4K8BaS9YVrTkA0trWtZJ+58lQT8IlTeEolD+FqFlS1mjkNqMfNECbQ9nUSRbfa2p8NHUh03hyiiLe7Q2r76BSCiz85mnsAdoY3eYjjGe6rsz59n8rmRqjElbVnZ38KPpPEnWegCnWSekUzh/mMemSdT2IbCHAPWv4YuBZid3Bj/bfrpniJws7RY0R1nosddYsFrFaT9Bsq5YXl0+YPrIwNopIzlZ+m3x6sdV4IUbhCivdNVga61fiWizXwRMr2Sa5S5=',
            "x-umidtoken": "TA589C70D0A8A47E88CFAF19718EDA9AED11CF5F9DE448695838A9943E0"
        }

    def get_contents(self, current):
        postData = {
            "ajax": "true",
            "page": "2",
            "spm": "a2o4l.home.cate_12_2.1.239e6db4wGmMoi"
        }
        url = "https://www.lazada.com.ph/shop-motorcycle-helmets"
        html = HttpUtils.do_request("GET", url, self.headers, postData)
        data_json = json.loads(html.text)

        for d in data_json['obj']['dataList']:
            batchId = d['batchId']
            markTaskId = d['markTaskId']
            taskId = d['taskId']

            data = {
                "taskId": taskId,
                "batchId": batchId,
                "markTaskId": markTaskId

            }
            cookies = self.get_cookie_dict("JSESSIONID=FF6F253524BCD759AB3FE463D5486421; reloadUrl=/biaozhu/task/myTask.html; sid=FE38789FD2544DF28FC37DF730CD1D33; currentUser=11112222841")
            html = requests.post("http://label.iflytek.com/biaozhu/task/mark-task/result", data=data, headers=self.headers)
            d = json.loads(html.text)
            self.badDataCount += d['obj']['badDataCount']
            self.goodDataCount += d['obj']['goodDataCount']
            print("goodDataCount:" + str(self.goodDataCount))
            print("badDataCount:" + str(self.badDataCount))


if __name__ == '__main__':
    test_get = Test_Get()
    for i in range(1, 100):
        print(i)
        test_get.get_contents(i)